package com.jinxiangyang.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jinxiangyang.annotation.OperateLog;
import com.jinxiangyang.domain.LiveCourseAccount;
import com.jinxiangyang.service.LiveCourseAccountService;
import com.jinxiangyang.utils.enums.BusinessType;
import com.jinxiangyang.utils.enums.OperatorType;
import com.jinxiangyang.utils.result.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 直播课程账号表（受保护信息） 前端控制器
 * </p>
 *
 * @author jinxiangyang
 * @since 2023-08-12
 */
@RestController
@RequestMapping("/live/account")
@Api(tags = "直播账号接口")

public class LiveCourseAccountController {


    @Autowired
    private LiveCourseAccountService liveCourseAccountService;





    @GetMapping("/{pageNumber}/{pageSize}")
    @ApiOperation(value = "分页查询LiveCourseAccount")
    @OperateLog(title = "直播账号接口",businessType = BusinessType.OTHER,operatorType = OperatorType.TEACHER)
    public AjaxResult getAccountListPageByLike(@PathVariable Long pageNumber,
                                           @PathVariable Integer pageSize,
                                           LiveCourseAccount account){
        IPage<LiveCourseAccount> liveCourseAccountIpage =  liveCourseAccountService.getAccountListPageByLike(pageNumber,pageSize,account);
        if( pageNumber > liveCourseAccountIpage.getPages()){
            liveCourseAccountIpage = liveCourseAccountService.getAccountListPageByLike(liveCourseAccountIpage.getPages(), pageSize,account);
        }
        return AjaxResult.success(liveCourseAccountIpage);
    }


    @PutMapping
    @ApiOperation(value = "更新直播用户")
    @OperateLog(title = "直播账号接口",businessType = BusinessType.UPDATE,operatorType = OperatorType.TEACHER)
    public  AjaxResult updateLiveAccount(@RequestBody LiveCourseAccount account){
       if( liveCourseAccountService.updateLiveCourseAccountById(account)){
           return  AjaxResult.success();
       }else{
           return  AjaxResult.error("更新失败");
       }
    }


    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除")
    @OperateLog(title = "直播账号接口",businessType = BusinessType.DELETE,operatorType = OperatorType.TEACHER)
    public  AjaxResult deleteLiveAccountById(@PathVariable Integer id){
        if( liveCourseAccountService.deleteLiveCourseAccountById(id)){
            return  AjaxResult.success();
        }else{
            return  AjaxResult.error("删除失败");
        }
    }


    @PostMapping
    @ApiOperation(value = "添加直播用户")
    @OperateLog(title = "直播账号接口",businessType = BusinessType.INSERT,operatorType = OperatorType.TEACHER)
    public AjaxResult insertLiveAccount(@RequestBody LiveCourseAccount liveCourseAccount){
        if( liveCourseAccountService.insertLiveCourseAccount(liveCourseAccount)){
            return  AjaxResult.success();
        }else{
            return  AjaxResult.error("添加失败");
        }
    }

}

